package com.lanhe.order.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lanhe.apply.domain.LhQingchuangApply;
import com.lanhe.apply.service.ILhQingchuangApplyService;
import com.lanhe.common.constant.Constants;
import com.lanhe.common.constant.HttpStatus;
import com.lanhe.common.core.domain.entity.LhMemberBase;
import com.lanhe.common.exception.ServiceException;
import com.lanhe.common.utils.DateUtils;
import com.lanhe.common.utils.StringUtils;
import com.lanhe.common.utils.qingchuang.QingChuangUtil;
import com.lanhe.common.utils.qingchuang.dto.QingChuangOrderDTO;
import com.lanhe.common.utils.qingchuang.vo.QingChuangOrderVO;
import com.lanhe.member.service.*;
import com.lanhe.order.domain.LhOrdersPool;
import com.lanhe.order.domain.LhOrdersQingchuang;
import com.lanhe.order.domain.LhOrdersQingchuangLog;
import com.lanhe.order.domain.dto.LhOrdersQingchuangDto;
import com.lanhe.order.domain.vo.LhOrdersQingchuangTaskVo;
import com.lanhe.order.mapper.LhOrdersQingchuangMapper;
import com.lanhe.order.service.ILhOrdersPoolService;
import com.lanhe.order.service.ILhOrdersQingchuangLogService;
import com.lanhe.order.service.ILhOrdersQingchuangService;
import com.lanhe.product.domain.LhQingchuangProductDetails;
import com.lanhe.product.service.ILhQingchuangProductDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.WeekFields;
import java.util.*;

/**
 * (LhOrdersQingchuang)表服务实现类
 *
 * @author zhanggl
 * @since 2023-12-20 22:33:40
 */
@Service
public class LhOrdersQingchuangServiceImpl extends ServiceImpl<LhOrdersQingchuangMapper, LhOrdersQingchuang> implements ILhOrdersQingchuangService {

	@Autowired
	private LhOrdersQingchuangMapper ordersQingchuangMapper;

	@Autowired
	private QingChuangUtil qingChuangUtil;

	@Autowired
	private ILhQingchuangProductDetailsService productDetailsService;

	@Autowired
	private ILhOrdersQingchuangLogService ordersQingchuangLogService;

	@Autowired
	private ILhQingchuangApplyService qingchuangApplyService;

	@Autowired
	private ILhOrdersPoolService ordersPoolService;

	@Autowired
	private ILhMemberBaseService memberBaseService;

	private final PlatformTransactionManager transactionManager;

	@Autowired
	public LhOrdersQingchuangServiceImpl(PlatformTransactionManager transactionManager) {
		this.transactionManager = transactionManager;
	}

	/**
	 * 订单列表
	 *
	 * @param ordersQingchuang 实体
	 * @return java.util.List<com.lanhe.order.domain.LhOrdersQingchuang>
	 * @author zhanggl
	 * @date 2023/12/20
	 */
	@Override
	public List<LhOrdersQingchuang> selectOrdersList(LhOrdersQingchuang ordersQingchuang) {

		LambdaQueryWrapper<LhOrdersQingchuang> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(ObjectUtil.isNotNull(ordersQingchuang.getMemberId()), LhOrdersQingchuang::getMemberId, ordersQingchuang.getMemberId());
		queryWrapper.eq(StringUtils.isNotBlank(ordersQingchuang.getApplyId()), LhOrdersQingchuang::getApplyId, ordersQingchuang.getApplyId());
		queryWrapper.eq(ObjectUtil.isNotNull(ordersQingchuang.getType()), LhOrdersQingchuang::getType, ordersQingchuang.getType());
		queryWrapper.eq(ObjectUtil.isNotNull(ordersQingchuang.getStatus()), LhOrdersQingchuang::getStatus, ordersQingchuang.getStatus());
		queryWrapper.like(StringUtils.isNotBlank(ordersQingchuang.getProductName()), LhOrdersQingchuang::getProductName, ordersQingchuang.getProductName());
		queryWrapper.orderByDesc(LhOrdersQingchuang::getOrderQingchuangId);
		return ordersQingchuangMapper.selectList(queryWrapper);
	}

	/**
	 * 新增报备数据
	 *
	 * @param qingChuangOrderDTO DTO
	 * @author zhanggl
	 * @date 2023/12/20
	 */
	@Override
	public void insertOrdersQingchuang(QingChuangOrderDTO qingChuangOrderDTO) {

		// 查询订单详情
		LhQingchuangProductDetails productDetails = productDetailsService.selectProductDetailByNumber(qingChuangOrderDTO.getNumber());
		if (ObjectUtil.isNull(productDetails)) {
			throw new ServiceException("详情数据查询异常", HttpStatus.ERROR);
		}

		// 生成订单号
		String orderNumber = DateUtils.generateOrderCode();

		// 新增提交订单
		LhOrdersQingchuang ordersQingchuang = new LhOrdersQingchuang();
		ordersQingchuang.setApplyId(qingChuangOrderDTO.getApplyId());
		ordersQingchuang.setOrderNumber(orderNumber);
		ordersQingchuang.setPid(productDetails.getId());
		ordersQingchuang.setNumber(qingChuangOrderDTO.getNumber());
		ordersQingchuang.setProductName(productDetails.getTitle());
		ordersQingchuang.setProductLog(productDetails.getThmub());
		ordersQingchuang.setMemberId(qingChuangOrderDTO.getMemberId());
		ordersQingchuang.setMobile(qingChuangOrderDTO.getMobile());
		ordersQingchuang.setSalesman(qingChuangOrderDTO.getSalesman());
		ordersQingchuang.setTaskNum(Constants.GeneralIntType.ONE.longValue());
		ordersQingchuang.setType(Constants.GeneralIntType.ONE);
		ordersQingchuang.setForm(JSON.toJSONString(qingChuangOrderDTO.getForm()));
		ordersQingchuang.setStatus(Constants.GeneralIntType.ZERO.toString());
		ordersQingchuang.setCompleteTime(new Date());
		ordersQingchuang.setCreateTime(new Date());
		ordersQingchuangMapper.insert(ordersQingchuang);

		qingChuangOrderDTO.setOrderNo(orderNumber);
		String suborder = qingChuangUtil.suborder(qingChuangOrderDTO);
		QingChuangOrderVO qingChuangOrderVO = JSONObject.parseObject(suborder, QingChuangOrderVO.class);
		if (!Constants.GeneralIntType.ONE.equals(qingChuangOrderVO.getCode())) {
			throw new ServiceException("订单提交异常->" + qingChuangOrderVO.getMsg(), HttpStatus.ERROR);
		}

		// 更新订单订单
		LambdaUpdateWrapper<LhOrdersQingchuang> updateWrapper = new LambdaUpdateWrapper<>();
		updateWrapper.eq(LhOrdersQingchuang::getOrderQingchuangId, ordersQingchuang.getOrderQingchuangId());
		LhOrdersQingchuang qingchuang = new LhOrdersQingchuang();
		qingchuang.setOrderQingchuangId(qingChuangOrderVO.getData());
		ordersQingchuangMapper.update(qingchuang, updateWrapper);
	}

	/**
	 * 订单结算数据回调
	 *
	 * @param ordersQingchuangDto DTO
	 * @author zhanggl
	 * @date 2023/12/21
	 */
	@Override
	public void settlementNotice(LhOrdersQingchuangDto ordersQingchuangDto) {

		Long orderQingchuangLogId = 0L;
		try {
			// 提交回调日志
			LhOrdersQingchuangLog qingchuangLog = new LhOrdersQingchuangLog();
			qingchuangLog.setType(ordersQingchuangDto.getType());
			qingchuangLog.setApikey(ordersQingchuangDto.getApikey());
			qingchuangLog.setDetail(ordersQingchuangDto.getDetail());
			qingchuangLog.setStatus(Constants.GeneralIntType.ZERO);
			qingchuangLog.setCreateTime(new Date());
			ordersQingchuangLogService.insertOrdersQingchuangLog(qingchuangLog);
			orderQingchuangLogId = qingchuangLog.getOrderQingchuangLogId();
			LhOrdersQingchuangDto.NewDetailBean detail = JSONObject.parseObject(ordersQingchuangDto.getDetail(), LhOrdersQingchuangDto.NewDetailBean.class);
			if (ObjectUtil.isNotNull(detail) && ObjectUtil.isNotEmpty(detail.getHeader()) && qingChuangUtil.getAppSecret().equals(ordersQingchuangDto.getApikey())) {

				// 提交订单回调数据明细 type=1
				if (Constants.GeneralIntType.ONE.equals(ordersQingchuangDto.getType())) {
					settlementOrderType1(detail);
				}

				// 结算订单回调数据明细 type=2
				if (Constants.GeneralIntType.TWO.equals(ordersQingchuangDto.getType())) {
					settlementOrderType2(detail);
				}
			}

			LhOrdersQingchuangLog orderLog = new LhOrdersQingchuangLog();
			orderLog.setOrderQingchuangLogId(orderQingchuangLogId);
			orderLog.setStatus(Constants.GeneralIntType.ONE);
			orderLog.setReason("正常");
			ordersQingchuangLogService.updateHandleStatus(orderLog);
		} catch (Exception e) {
			System.out.println(e.getMessage());
			System.out.println("ID=>>>>>>>>" + orderQingchuangLogId);
			LhOrdersQingchuangLog orderLog = new LhOrdersQingchuangLog();
			orderLog.setOrderQingchuangLogId(orderQingchuangLogId);
			orderLog.setStatus(Constants.GeneralIntType.TWO);
			orderLog.setReason(e.getMessage());
			ordersQingchuangLogService.updateHandleStatus(orderLog);
		}
	}

	/**
	 * 订单结算数据回调-提交订单
	 *
	 * @param newDetail DTO
	 * @author zhanggl
	 * @date 2023/12/21
	 */
	public void settlementOrderType1(LhOrdersQingchuangDto.NewDetailBean newDetail) {

		TransactionStatus transactionStatus = transactionManager.getTransaction(new DefaultTransactionDefinition());

		try {

			// 处理回调数据
			for (int i = 0; i < newDetail.getData().size(); i++) {

				// 订单号
				String orderNumber = newDetail.getData().get(i).get(0);

				// 状态
				String status = newDetail.getData().get(i).get(1);

				// 结束日期
				String settlementTime = newDetail.getData().get(i).get(2);

				// 备注
				String reason = newDetail.getData().get(i).get(3);

				// 政策
				String taskPolicy = newDetail.getData().get(i).get(4);

				// 作业数量
				String taskNum = newDetail.getData().get(i).get(5);

				Map<String, String> statusMap = new HashMap<>();
				statusMap.put("待处理", "0");
				statusMap.put("已结算", "1");
				statusMap.put("未通过", "2");
				LhOrdersQingchuang order = getOrderByOrderNumber(orderNumber);
				if (ObjectUtil.isNull(order)) {
					throw new ServiceException("订单数据查询异常", HttpStatus.ERROR);
				}

				// 查询订单详情
				LhQingchuangProductDetails productDetails = productDetailsService.selectProductDetailByNumber(order.getNumber());
				if (ObjectUtil.isNull(productDetails)) {
					throw new ServiceException("详情数据查询异常", HttpStatus.ERROR);
				}

				BigDecimal profit = new BigDecimal("0.0");
				if (Constants.GeneralIntType.ONE.toString().equals(statusMap.get(status))) {
					String task = productDetails.getTask();
					List<LhOrdersQingchuangTaskVo> taskVo = JSONArray.parseArray(task, LhOrdersQingchuangTaskVo.class);
					if (ObjectUtil.isNull(taskVo)) {
						throw new ServiceException("佣金政策查询异常", HttpStatus.ERROR);
					}
					for (LhOrdersQingchuangTaskVo vo : taskVo) {
						if (vo.getAlias().equals(taskPolicy)) {
							profit = new BigDecimal(vo.getPrice() * Long.parseLong(taskNum));
						}
					}
				}

				// 处理日期格式
				boolean flag = false;
				if (settlementTime.contains("/")) {
					flag = DateUtils.isValidDateFormat(settlementTime, "yyyy/MM/dd");
				}
				if (settlementTime.contains("-")) {
					flag = DateUtils.isValidDateFormat(settlementTime, "yyyy-MM-dd");
					if (flag) {
						Date format2 = null;
						try {
							format2 = new SimpleDateFormat("yyyy-MM-dd").parse(settlementTime);
						} catch (ParseException e) {
							throw new RuntimeException(e);
						}
						settlementTime = new SimpleDateFormat("yyyy/MM/dd").format(format2);
					}
				}
				if (!flag) {
					settlementTime = DateUtils.excelDoubleToDate(settlementTime);
				}

				order.setStatus(statusMap.get(status));
				order.setReason(reason);
				order.setTaskType(status);
				order.setTaskPolicy(taskPolicy);
				order.setTaskNum(Long.valueOf(taskNum));
				order.setProfit(profit);
				order.setSettlementTime(new Date(settlementTime));
				order.setUpdateTime(new Date());
				int num = ordersQingchuangMapper.updateById(order);
				if (num == 0) {
					throw new ServiceException("订单更新异常", HttpStatus.ERROR);
				}

				DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
				LocalDate date = LocalDate.parse(settlementTime, formatter);
				String year = date.getYear() + "";
				String yearMonth = StringUtils.join(date.getYear(), date.getMonthValue());
				String yearMonthDay = StringUtils.join(date.getYear(), date.getMonthValue(), date.getDayOfMonth());

				// 获取当前日期-周
				WeekFields weekFields = WeekFields.of(Locale.getDefault());
				Integer currentWeek = date.get(weekFields.weekOfWeekBasedYear());

				// 添加主订单
				LhOrdersPool ordersPool = new LhOrdersPool();
				ordersPool.setOrderNumber(order.getOrderNumber());
				ordersPool.setMemberId(order.getMemberId());
				ordersPool.setOrigin(Constants.ORDERS_ORIGIN_QINGCHUANG);
				ordersPool.setOrderId(order.getOrderId());
				ordersPool.setRevenueType(Constants.ORDERS_REVENUE_TYPE_0);
				ordersPool.setProductName(order.getProductName());
				ordersPool.setProductLog(order.getProductLog());
				ordersPool.setYear(Integer.valueOf(year));
				ordersPool.setMonthly(Integer.valueOf(yearMonth));
				ordersPool.setWeekly(currentWeek);
				ordersPool.setDaily(Integer.valueOf(yearMonthDay));

				// todo 需要记录区分金额比例分配---后期优化
				ordersPool.setMediaAmount(order.getProfit());
				ordersPool.setAmount(order.getProfit());
				ordersPool.setStatus(Constants.GeneralIntType.ONE.toString().equals(order.getStatus()) ? Constants.ORDERS_POOL_STATUS_1 : Constants.ORDERS_POOL_STATUS_0);
				ordersPool.setReason(order.getReason());
				ordersPoolService.insertOrdersPool(ordersPool);

				// 更新会员收益
				if (Constants.GeneralIntType.ONE.toString().equals(order.getStatus())) {
					memberBaseService.updateMemberBenefits(ordersPool);
				}
			}
			// 提交订单
			transactionManager.commit(transactionStatus);
		} catch (RuntimeException e) {
			transactionManager.rollback(transactionStatus);
			throw new ServiceException("处理异常=>" + e.getMessage());
		}
	}

	/**
	 * 订单结算数据回调-结算订单
	 *
	 * @param newDetail DTO
	 * @author zhanggl
	 * @date 2023/12/21
	 */
	public void settlementOrderType2(LhOrdersQingchuangDto.NewDetailBean newDetail) {

		TransactionStatus transactionStatus = transactionManager.getTransaction(new DefaultTransactionDefinition());
		try {

			// 处理回调数据
			for (int i = 0; i < newDetail.getData().size(); i++) {

				// 结算时间
				String settlementTime = newDetail.getData().get(i).get(0);

				// 做单时间
				String completeTime = newDetail.getData().get(i).get(1);

				// 渠道ID
				String channelId = newDetail.getData().get(i).get(2);

				// 产品编号
				String number = newDetail.getData().get(i).get(3);

				// 链接-平台传输的会员手机号
				String link = newDetail.getData().get(i).get(4);

				// 结算系数
				String settlementCoefficient = newDetail.getData().get(i).get(5);

				// 任务类型
				String taskType = newDetail.getData().get(i).get(6);

				// 业务员
				String salesman = newDetail.getData().get(i).get(7);

				// 复登率
				String reRegistrationRate = newDetail.getData().get(i).get(8);

				// 处理佣金 todo 处理金额-后期需要分配佣金比例
				List<Map<String, String>> taskPolicyMaps = new ArrayList<>();
				for (int j = 0; j < newDetail.getHeader().size(); j++) {
					if (j > 8 && StringUtils.isNotBlank(newDetail.getHeader().get(j))) {
						Map<String, String> stringIntegerMap = new HashMap<>();
						stringIntegerMap.put("taskName", newDetail.getHeader().get(j));
						stringIntegerMap.put("taskValue", newDetail.getData().get(i).get(j));
						taskPolicyMaps.add(stringIntegerMap);
					}
				}

				// 查询用户数据
				LhMemberBase userByMobile = memberBaseService.getUserByMobile(link);
				if (ObjectUtil.isNull(userByMobile)) {
					throw new ServiceException("用户数据查询异常", HttpStatus.ERROR);
				}

				// 查询订单详情
				LhQingchuangProductDetails productDetails = productDetailsService.selectProductDetailByNumber(number);
				if (ObjectUtil.isNull(productDetails)) {
					throw new ServiceException("详情数据查询异常", HttpStatus.ERROR);
				}

				// 查询报备信息
				LhQingchuangApply qingchuangApply = qingchuangApplyService.selectApplyByMobileAndSalesman(userByMobile.getMobile(), salesman);
				if (ObjectUtil.isNull(qingchuangApply)) {
					throw new ServiceException("报备数据查询异常", HttpStatus.ERROR);
				}

				Map<String, String> statusMap = new HashMap<>();
				statusMap.put("待处理", "0");
				statusMap.put("已结算", "1");
				statusMap.put("已完成", "1");
				statusMap.put("未通过", "2");

				// 处理佣金 todo 处理金额-后期需要分配佣金比例
				BigDecimal profit = BigDecimal.ZERO;
				BigDecimal settlementCoefficientDecimal = new BigDecimal(settlementCoefficient);

				if (Constants.GeneralIntType.ONE.toString().equals(statusMap.get(taskType)) && settlementCoefficientDecimal.compareTo(BigDecimal.ZERO) > 0) {
					String task = productDetails.getTask();
					List<LhOrdersQingchuangTaskVo> taskVo = JSONArray.parseArray(task, LhOrdersQingchuangTaskVo.class);

					if (ObjectUtil.isNull(taskVo)) {
						throw new ServiceException("佣金政策查询异常", HttpStatus.ERROR);
					}

					for (LhOrdersQingchuangTaskVo vo : taskVo) {
						for (Map<String, String> taskPolicyMap : taskPolicyMaps) {
							if (vo.getAlias().equals(taskPolicyMap.get("taskName"))) {

								// 处理佣金 todo 处理金额-后期需要分配佣金比例
								// 结算订单佣金计算公式:佣金政策对应的原始佣金*结算系数(0~1)*作业数量
								BigDecimal newProfit = BigDecimal.valueOf(vo.getPrice()).multiply(settlementCoefficientDecimal).multiply(new BigDecimal(taskPolicyMap.get("taskValue")));
								profit = profit.add(newProfit);
							}
						}
					}
				}

				LhOrdersQingchuang orders = new LhOrdersQingchuang();
				orders.setApplyId(qingchuangApply.getApplyId());
				orders.setOrderNumber(DateUtils.generateOrderCode());
				orders.setPid(productDetails.getId());
				orders.setNumber(productDetails.getNumber());
				orders.setProductName(productDetails.getTitle());
				orders.setProductLog(productDetails.getThmub());
				orders.setLink(link);
				orders.setChannelId(channelId);
				orders.setReRegistrationRate(reRegistrationRate);
				orders.setMemberId(userByMobile.getMemberId());
				orders.setMobile(userByMobile.getMobile());
				orders.setSalesman(salesman);
				orders.setTaskType(taskType);
				orders.setTaskPolicy(JSON.toJSONString(taskPolicyMaps));
				orders.setType(Constants.GeneralIntType.TWO);
				orders.setProfit(profit);
				orders.setStatus(statusMap.get(taskType));

				// 处理日期格式-做单日期
				boolean flag = false;
				if (completeTime.contains("/")) {
					flag = DateUtils.isValidDateFormat(completeTime, "yyyy/MM/dd");
				}
				if (completeTime.contains("-")) {
					flag = DateUtils.isValidDateFormat(completeTime, "yyyy-MM-dd");
					if (flag) {
						Date format2 = new SimpleDateFormat("yyyy-MM-dd").parse(settlementTime);
						completeTime = new SimpleDateFormat("yyyy/MM/dd").format(format2);
					}
				}
				if (!flag) {
					completeTime = DateUtils.excelDoubleToDate(completeTime);
				}
				orders.setCompleteTime(new Date(completeTime));

				// 处理日期格式-结算日期
				boolean flag1 = false;
				if (settlementTime.contains("/")) {
					flag1 = DateUtils.isValidDateFormat(settlementTime, "yyyy/MM/dd");
				}
				if (settlementTime.contains("-")) {
					flag1 = DateUtils.isValidDateFormat(settlementTime, "yyyy-MM-dd");
					if (flag1) {
						Date format2 = new SimpleDateFormat("yyyy-MM-dd").parse(settlementTime);
						settlementTime = new SimpleDateFormat("yyyy/MM/dd").format(format2);
					}
				}
				if (!flag1) {
					settlementTime = DateUtils.excelDoubleToDate(settlementTime);
				}
				orders.setSettlementTime(new Date(settlementTime));
				orders.setCreateTime(new Date());

				int num = ordersQingchuangMapper.insert(orders);
				if (num == 0) {
					throw new ServiceException("订单添加异常", HttpStatus.ERROR);
				}

				DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
				LocalDate date = LocalDate.parse(settlementTime, formatter);
				String year = date.getYear() + "";
				String yearMonth = date.getYear() + "" + date.getMonthValue();
				String yearMonthDay = date.getYear() + "" + date.getMonthValue() + "" + date.getDayOfMonth();

				// 获取当前日期-周
				WeekFields weekFields = WeekFields.of(Locale.getDefault());
				Integer currentWeek = date.get(weekFields.weekOfWeekBasedYear());


				// 添加主订单
				LhOrdersPool ordersPool = new LhOrdersPool();
				ordersPool.setOrderNumber(orders.getOrderNumber());
				ordersPool.setMemberId(orders.getMemberId());
				ordersPool.setOrigin(Constants.ORDERS_ORIGIN_QINGCHUANG);
				ordersPool.setOrderId(orders.getOrderId());
				ordersPool.setRevenueType(Constants.ORDERS_REVENUE_TYPE_0);
				ordersPool.setProductName(orders.getProductName());
				ordersPool.setProductLog(orders.getProductLog());
				ordersPool.setYear(Integer.valueOf(year));
				ordersPool.setMonthly(Integer.valueOf(yearMonth));
				ordersPool.setWeekly(currentWeek);
				ordersPool.setDaily(Integer.valueOf(yearMonthDay));

				ordersPool.setMediaAmount(orders.getProfit());
				ordersPool.setAmount(orders.getProfit());
				ordersPool.setStatus(Constants.GeneralIntType.ONE.toString().equals(orders.getStatus()) ? Constants.ORDERS_POOL_STATUS_1 : Constants.ORDERS_POOL_STATUS_0);
				ordersPool.setReason(orders.getReason());
				ordersPoolService.insertOrdersPool(ordersPool);

				// 更新会员收益
				if (Constants.GeneralIntType.ONE.toString().equals(orders.getStatus())) {
					memberBaseService.updateMemberBenefits(ordersPool);
				}

			}

			// 提交订单
			transactionManager.commit(transactionStatus);
		} catch (Exception e) {
			transactionManager.rollback(transactionStatus);
			throw new ServiceException("处理异常=>" + e.getMessage());
		}
	}

	/**
	 * 根据订单编号查询订单
	 *
	 * @param orderNumber 订单编号
	 * @return 结果
	 * @author zhanggl
	 * @date 2023/12/21
	 */
	private LhOrdersQingchuang getOrderByOrderNumber(String orderNumber) {
		LambdaQueryWrapper<LhOrdersQingchuang> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(LhOrdersQingchuang::getOrderNumber, orderNumber);
		return ordersQingchuangMapper.selectOne(queryWrapper);
	}

}



